/* Replication Do-file for: Unbreakable Legacies? Redistricting, Political Capital and Political Dynasties */
/* Version: v1.0 */
/* Date: May 2024 */
***********************************


***********************************
***********************************
* set path to data:
*cd ""
use unbreaklegacies_replication_may2024.dta, clear

* install rd packages:
net install st0366_1, all replace force from(http://www.stata-journal.com/software/sj17-2)

***********************************
***********************************

* Analysis

***********************************
***********************************

***********************************
* set path to tables:
*cd ""
***********************************

* sumstats

sum above15 above50 maxoldinnewpop retired raninParl23 reelect_new future_relative immediatefuture_relative upto1918_relative partisanchange labour_everafter85, sep(0)
sum reelect_new if raninParl23==1, sep(0)

***********************************
* main reduced form RD

foreach var of varlist future_relative immediatefuture_relative upto1918_relative retired raninParl23 reelect_new partisanchange {
rdrobust `var'  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
}
rdrobust reelect_new population if raninParl23==1, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 

* main reduced form RD more outcomes
foreach var of varlist nrcompetitors23 totalnrseats23 unopposed23 marginvote23 raninsamenewconstid totaltenure  {
rdrobust `var'  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
}

***********************************
* RD_IV maxpop

rdrobust future_relative population, fuzzy(maxoldinnewpop) c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
foreach var of varlist immediatefuture_relative upto1918_relative retired raninParl23 reelect_new partisanchange {
rdrobust `var'  population, fuzzy(maxoldinnewpop) c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
}
rdrobust reelect_new population if raninParl23==1, fuzzy(maxoldinnewpop) c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 

foreach var of varlist nrcompetitors23 totalnrseats23 unopposed23 marginvote23 raninsamenewconstid {
rdrobust `var'  population, fuzzy(maxoldinnewpop) c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
}
rdrobust totaltenure population, fuzzy(maxoldinnewpop) c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 

***********************************
* heterogeneous

foreach var of varlist loyaltogov retired retiredloyal raninParl23 {
preserve
keep if `var'==1
tab `var'
rdrobust future_relative  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
restore
}
